package com.zhxh.nzpos.setting;

import java.util.ArrayList;
import java.util.Iterator;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.ListView;

import com.zhxh.nzpos.BaseActivity;
import com.zhxh.nzpos.R;
import com.zhxh.nzpos.dao.MemberDao;
import com.zhxh.nzpos.model.Member;

/**
 * 设置中的操作员设定界面
 * 
 * @author wangzt
 *
 */
public class MemberListActivity extends   BaseActivity {

	private ArrayList<Member> memberItems;
	
	private ArrayList<Member> selectedItems;
	private MemberSettingAdapter listAdapter;
	
	MemberDao memberDao;
	
	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_operator_member_select);
        memberDao = new MemberDao(this);
        initViews();
    }
	
	private void initViews() {
		ListView listView = (ListView) findViewById(R.id.operator_listview);
		initData();
		listAdapter = new MemberSettingAdapter(getLayoutInflater(), memberItems);
		listView.setAdapter(listAdapter);
		 listView.setItemsCanFocus(false);
		listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
		
	
		
		ImageView settleBtn = (ImageView) findViewById(R.id.operator_ok_btn);
		settleBtn.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				// TODO计算并传递参数到SettleAccountActivity
				Log.i("selcted........", ""+listAdapter.isSelected.size());
				
				  Iterator<Integer> iterator = listAdapter.isSelected.keySet().iterator();  
					Intent i = new Intent();
					Bundle b = new Bundle();
					  Integer key = null;
		            while (iterator.hasNext()) {    
		             key = iterator.next();    
		                      
		            }           
		            if(key != null)
		        	b.putSerializable("member", memberItems.get(key));	
			
			
				i.putExtras(b);

				setResult(RESULT_OK, i);
				finish();
			}
		});
/*		ImageView cancelBtn = (ImageView) findViewById(R.id.operator_cancel_btn);
		cancelBtn.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				finish();
			}
		});*/
	}
	private void initData() {
		//memberItems = new ArrayList<Member>();
	//	DBHelper dbHelper = new DBHelper(getApplicationContext());
		//dbHelper.openDatabase();	
		selectedItems = new ArrayList();
		memberItems = (ArrayList)memberDao.getAll();
		System.out.println("memberItems====="+memberItems);
		// Log.i("aaaaaaaaaaaaaa=============", memberItems);
		// Log.i("bbbbbbbbbbbbbbbbbbbbbb=============", memberItems.size());
		
	}
	
}
